package com.jsonal.controller;


import com.jsonal.entity.api.TagsBean;
import com.jsonal.form.TagsForm;
import com.jsonal.service.TagsService;
import com.jsonal.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author auto
 * @since 2020-04-20
 */
@RestController
public class TagsController extends BaseController {


    @Autowired
    private TagsService tagsService;

    @GetMapping("/api/getTagsList")
    public Result getTagsList() {
        return tagsService.getTagsList(null);
    }

    @GetMapping("/managers/getTagsList")
    public Result tagsList(TagsForm tagsForm) {
        TagsBean tagsBean = new TagsBean();
        this.setFormToBean3(tagsForm, tagsBean);
        return tagsService.getTagsList(tagsBean);
    }

    @PostMapping("/managers/addOrUpdateTag")
    public Result addOrUpdate(@RequestBody TagsForm tagsForm) {
        TagsBean tagsBean = new TagsBean();
        this.setFormToBean3(tagsForm, tagsBean);
        return tagsService.addOrUpdate(tagsBean);
    }

    @GetMapping("/managers/getTagById/{id}")
    public Result getTagById(@PathVariable Integer id) {
        if (id == 0) {
            return new Result(false, "id错误!");
        }
        return tagsService.getTagById(id);
    }

    @GetMapping("/managers/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        if (id == 0) {
            return new Result(false, "id 错误");
        }
        return tagsService.deleteById(id);
    }
}
